package webu

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"time"
)

// 得到整数
func Geti(c *gin.Context, param string) int {
	var intv, _ = strconv.Atoi(c.DefaultQuery(param, "0"))
	return intv
}

func Geti32(c *gin.Context, param string) int32 {
	var intv, _ = strconv.Atoi(c.DefaultQuery(param, "0"))
	//clog.Info("webu,Geti32,param=", param)
	//clog.Info("webu,Geti32,intv=", intv)
	return int32(intv)
}

func Geti64(c *gin.Context, param string) int64 {
	var intv, _ = strconv.Atoi(c.DefaultQuery(param, "0"))
	//clog.Info("webu,Geti64,param=", param)
	//clog.Info("webu,Geti64,intv=", intv)
	return int64(intv)
}

// 得到int8
func Getb(c *gin.Context, param string) int8 {
	var intv, _ = strconv.Atoi(c.DefaultQuery(param, "0"))
	//clog.Info("webu,Getb,param=", param)
	//clog.Info("webu,Getb,intv=", intv)
	return int8(intv)
}

// 得到int8字符串
func Getbs(c *gin.Context, param string) string {
	//clog.Info("webu,Getbs,param=", param)
	//clog.Info("webu,Getbs,result=", c.DefaultQuery(param, "0"))
	return c.DefaultQuery(param, "0")
}

// 得到字符串
func Gets(c *gin.Context, param string) string {
	//clog.Info("webu,Gets,param=", param)
	//clog.Info("webu,Gets,result=", c.DefaultQuery(param, ""))
	return c.DefaultQuery(param, "")
}

// 得到字符串
func Getsd(c *gin.Context, param string, defaultValue string) string {
	//clog.Info("webu,Gets,param=", param)
	//clog.Info("webu,Gets,result=", c.DefaultQuery(param, ""))
	return c.DefaultQuery(param, defaultValue)
}

// 得到日期时间
func Getdo(c *gin.Context, param string) time.Time {
	//clog.Info("webu,Getdo,param=", param)
	var timeQ = c.DefaultQuery(param, "0")
	if timeQ == "0" {
		//clog.Info("webu,Getdo,result=", time.Now())
		return time.Now()
	} else {
		var retunTime, _ = time.Parse(time.DateTime, timeQ)
		//clog.Info("webu,Getdo,result=", retunTime)
		return retunTime
	}
}
